//
//  WDLog.h
//  Wi-Fi_Disk
//
//  Created by Snow on 14-6-9.
//  Copyright (c) 2014年 LiuMaoWen. All rights reserved.
//

#import <Foundation/Foundation.h>

/*
 * 定义各个模块
 */
#define LOG_OFF                       ((long long)1 << 0)                //关闭日志
#define LOG_EXCEPTION                 ((long long)1 << 1)                //各个模块出现异常
// iStorage/uStorage相关模块
#define LOG_MODUL_ISTORAGE            ((long long)1 << 2)                //认盘模块
#define LOG_MODUL_ISTORAGE_HTTP       ((long long)1 << 3)               //HTTP_SERVER
// 上层UI相关
#define LOG_CAMERA_DATASOURCE         ((long long)1 << 4)                //摄像头数据源
#define LOG_UI_DEBUG                  ((long long)1 << 5)                //UI调试
#define LOG_MODUL_TRANSFER            ((long long)1 << 6)                //传输模块
#define LOG_MODUL_SYSTEM_DATASOURCE   ((long long)1 << 7)                //系统数据源获取
#define LOG_MODUL_THUMB               ((long long)1 << 8)                //缩略图相关
#define LOG_MODUL_VIDEO               ((long long)1 << 9)                //视频播放模块
#define LOG_MODUL_VIDEO_RECORD        ((long long)1 << 10)                //视频录制模块
#define LOG_MODUL_MUSIC               ((long long)1 << 11)               //音乐模块
// 搜索库/通讯库
#define LOG_MODUL_LOGIN               ((long long)1 << 12)               //注册登录模块
#define LOG_MODUL_Dll                 ((long long)1 << 13)               //设备搜索/底层通讯模块
#define LOG_MODUL_BACKUP              ((long long)1 << 14)               //相册/通讯录备份模块
// 数据库
#define LOG_MODUL_DATABASE            ((long long)1 << 15)               //数据库模块
#define LOG_MODUL_N390                ((long long)1 << 16)

// iStorage/uStorage底层库日志
#define LOG_MODUL_USBHOST             ((long long)1 << 26)               //底层缓存库日志
#define LOG_MODUL_FAT32               ((long long)1 << 30)               //FAT32 功能 龙工底层库log
#define LOG_MODUL_USB_CACHE           ((long long)1 << 31)               // CACHE库日志

#define LOG_ALL                       ((long long)0xffffffff)    //开启所有日志

#define LOG_MODUL_MAIN              ((int64_t)1 << 16)                //主框架模块
#define LOG_MODUL_DLNA              ((int64_t)1 << 16)                //DLNA模块
#define LOG_MODUL_PICTURE           ((int64_t)1 << 16)                //图片模块
#define LOG_MODUL_SDCARD            ((int64_t)1 << 16)                //sdcard模块
#define LOG_MODUL_P2P               ((int64_t)1 << 16)               //P2P
#define LOG_MODUL_CHROMECAST        ((int64_t)1 << 16)               //chrome cast
#define LOG_MODUL_AIRPLAY           ((int64_t)1 << 16)               //AIRPLAY
#define LOG_MODUL_SYSTEMOPT         ((int64_t)1 << 16)               //二维码
#define LOG_MODUL_DATASOURCE        ((int64_t)1 << 16)               //数据源获取
#define LOG_MODUL_FRAME             ((int64_t)1 << 16)               //界面调试相关
#define LOG_MODUL_PHISON            ((int64_t)1 << 16)               //istorage phison
#define LOG_MODUL_PL2733            ((int64_t)1 << 16)               //istorage PL2733
#define LOG_MODUL_IFAT32            ((int64_t)1 << 16)               //istorage IFAT32
#define LOG_MODUL_OTHER             ((int64_t)1 << 16)               //其它相关
#define LOG_MODUL_COMMANDSAVE       ((int64_t)1 << 16)               //命令发送保持相关
#define LOG_UI_DETECTED             ((int64_t)1 << 16)               //检测自动化测试工具
#define LOG_MODUL_TEST_SPEED        ((int64_t)1 << 16)               //速度测试工具
#define LOG_MODUL_DOWNLOAD          ((int64_t)1 << 16)               //百度云下载

#define LOG_MODUL_JUST_TEST         ((int64_t)1 << 16)               //日志测试


/// 旧版本日志
#define WDLog(MODUL, frmt, ...) \
        do { [WDShareLogger log:MODUL file:__FILE__ function:__FUNCTION__ line:__LINE__ format:(frmt), ##__VA_ARGS__]; } while(0)

/// 日志等级
typedef NS_ENUM(NSInteger, WDLogLevel)
{
    WDLogLevelOff       = 0,
    /// Error logs only
    WDLogLevelError,
    /// Error and warning logs
    WDLogLevelWarning,
    /// Error, warning and info logs
    WDLogLevelInfo,
};

typedef NS_ENUM(NSUInteger, WDLogFlag){
    /// 0...00001 DDLogFlagError
    WDLogFlagError,
    /// 0...00010 DDLogFlagWarning
    WDLogFlagWarning,
    /// 0...00100 DDLogFlagInfo
    WDLogFlagInfo,
};

#define WDLog_ANY(tag, flg, frmt, ...) \
        do { [WDShareLogger logWithTag:tag flag:flg file:__FILE__ function:__FUNCTION__ line:__LINE__ format:(frmt), ##__VA_ARGS__]; } while(0)

/// 所有模块都会打印, 不受logModul属性控制,即使logModul为OFF,也会打印
#define WDLogError(tag, frmt, ...)   WDLog_ANY(tag, WDLogFlagError,      frmt, ##__VA_ARGS__);
#define WDLogWarn(tag, frmt, ...)    WDLog_ANY(tag, WDLogFlagWarning,    frmt, ##__VA_ARGS__);
#define WDLogInfo(tag, frmt, ...)    WDLog_ANY(tag, WDLogFlagInfo,       frmt, ##__VA_ARGS__);

#define WDShareLogger [WDLog sharedInstance]

/// 日志消息通知
FOUNDATION_EXTERN NSNotificationName const _Nonnull WDLogMessageNotification;

@class WDLogTags;
@interface WDLog : NSObject

/// 标志, 区分不同功能模块
@property (nonnull, nonatomic, strong, readonly) WDLogTags *logTag;

/// 文件日志开关, 默认关 (关闭文件日志, 不影响控制台日志)
@property (nonatomic, assign) BOOL fileLogSwitch;

/// 日志等级, 默认 WDLogLevelAll, 即 打印所有等级的日志,
@property (nonatomic, assign) WDLogLevel logLevel;

/// 开启日志广播,  每一条日志会通过 WDLogMessageNotification 发出
@property (nonatomic, assign) BOOL logNotifiy;

/// 显示实时日志窗口
@property (nonatomic, assign) BOOL viewConsole;

/// 文件日志文件夹
@property (nonnull, copy, readonly) NSString *logFolder;

+ (instancetype _Nonnull )sharedInstance;

/// 将日志信息写到文件中
/// @param flag 当前这条日志所属的警告类型
/// @param file 记录日志所在的文件
/// @param function 记录日志所在的函数名称
/// @param line 记录日志所在的行号
/// @param format 日志内容，格式化字符串
- (void)logWithTag:(NSString *_Nonnull)tag flag:(WDLogFlag)flag file:(const char *_Nonnull)file function:(const char *_Nonnull)function line:(int)line format:(NSString *_Nonnull)format, ... NS_FORMAT_FUNCTION(6,7);

/// 显示Log配置界面
- (void)showConfigureView;



#pragma mark - Deprecated
/// 筛选打印某个模块的日志,  被过滤的模块日志不会打印,也不会写入日志文件
@property (nonatomic,assign) int32_t logLevelValue DEPRECATED_MSG_ATTRIBUTE("use -logLevel");
@property (nonatomic,assign) long long logModul DEPRECATED_MSG_ATTRIBUTE("use -logTag");;

/// 旧版本接口, 底层日志对接此接口
/// 将日志信息写到文件中
/// @param modul 当前模块号
/// @param file 记录日志所在的文件
/// @param function 记录日志所在的函数名称
/// @param line 记录日志所在的行号
/// @param format 日志内容，格式化字符串
- (void)log:(long long)modul file:(const char *_Nonnull)file function:(const char *_Nonnull)function line:(int)line format:(NSString *_Nonnull)format, ... NS_FORMAT_FUNCTION(5,6);


@end



